package com.uml.umlwork.controller;


import com.uml.umlwork.dto.teacher.UmlTeacherDTO;
import com.uml.umlwork.service.TeacherService;
import com.uml.umlwork.utils.SystemMsgJsonResponse;
import com.uml.umlwork.vo.teacher.TeacherInfoVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wuze
 * @since 2021-01-04
 */
@RestController
@RequestMapping("/api/v1/umlwork/teachers")
public class TeacherController {
    private final TeacherService teacherService;

    public TeacherController(TeacherService teacherService) {
        this.teacherService = teacherService;
    }

    @GetMapping("/getAllTeacher")
    @ApiOperation(value = "[管理员] - 查询所有培训师", httpMethod = "GET")
    public SystemMsgJsonResponse getAllTeacher(@RequestParam(value = "page",defaultValue = "1L") Long page,
                                               @RequestParam(value = "size",defaultValue = "10L") Long size) {
        return SystemMsgJsonResponse.success(teacherService.getAllTeacher(page,size));
    }

    @GetMapping("/getTeacherByType")
    @ApiOperation(value = "根据类型查询培训师",httpMethod = "GET",response = TeacherInfoVO.class)
    public SystemMsgJsonResponse getTeacherByType(@RequestParam("type") String type){
        return SystemMsgJsonResponse.success(teacherService.getTeacherByType(type));
    }

    @PostMapping("/updateTeacher")
    @ApiOperation(value = "[管理员]-编辑培训师信息",httpMethod = "POST")
    public SystemMsgJsonResponse updateTeacherById(@RequestBody @Validated UmlTeacherDTO dto){
        teacherService.updateInfo(dto);
        return SystemMsgJsonResponse.success();
    }

    @PostMapping("/deleteTeacher/{id}")
    @ApiOperation(value = "[管理员] - 删除培训师", httpMethod = "POST")
    public SystemMsgJsonResponse deleteTeacherById(
            @PathVariable String id){
        teacherService.deleteTeacherByIdTeacher(id);
        return SystemMsgJsonResponse.success();
    }

}

